from commons.baseApi import BaseApi
from configtt.configs import NAME_PWD
from libs.login import Login
from utils.handle_excel_3 import testData_path
import  os
class Shop(BaseApi):  #继承
    # 1 - 列出店铺
    # 2 - 更新店铺
    '''
    店铺更新接口： 数据从用例文件去读取 excel/yamls
        1 -id 需要代码里去更新  --  字典可以更新值
        2 - 图片信息需要传入s
    '''

    def update(self,inData,shopID,fileInfo):   #修改商铺信息
        #1 - 更新店铺id
        inData['id'] = shopID
        if inData['id'] == 'id不存在':
            inData['id'] = '0'
        else:
            #更新店铺id
            inData['id'] = shopID
        #2 更新文件信息
        inData['image_path'] = fileInfo
        inData['image'] = f'/file/getImgStream?fileName={fileInfo}'
        return super(Shop,self).update(inData) #调用父类的方法

if __name__ == '__main__':
     # print(Shop().add())  #self.data 对应 baseApi
     #1 - 登录操作
     token = Login().login(NAME_PWD,getToken=True)
     # print(token)

     #2 = 创建店铺实例
     shop = Shop(token)

     #3 - 列出店铺
     testData = {'page':1,'limit':20}
     res = shop.query(testData)
     # print(res)
    #-----获取店铺id-------
     shopID = res['data']['records'][0]['id']
     # print('获取当前店铺id',res['data']['records'][0]['id'])

    #文件
     filedd = os.path.join(testData_path,'123.jpg')
     # print(filedd)
     res1 = shop.file_upload(filedd)   # 店铺
     fileInfo = res1['data']['realFileName']
     # print(res1['data']['realFileName'])   #图片信息

     #5 更新店铺  图片   改完之后退出去在进去图片才更新
     shopdata = {
            "name": "星巴克新建店",
            "address": "上海市静安区秣陵路303号",
            "id": "3269",
            "Phone": "13176876632",
            "rating": "5.0",
            "recent_order_num":100,
            "category": "快餐便当/简餐",
            "description": "满30减5，满60减8",
            "image_path": "b8be9abc-a85f-4b5b-ab13-52f48538f96c.png",
            "image": "http://121.41.14.39:8082/file/getImgStream?fileName=b8be9abc-a85f-4b5b-ab13-52f48538f96c.png"
        }
     res3 = shop.update(shopdata,shopID,fileInfo)
     # print(res3)
     print(shop.data)


